package com.housekeeping.housekeeping.wxPay.controller;

import com.housekeeping.housekeeping.serviceItem.utils.RequestUtils;
import com.housekeeping.housekeeping.serviceItem.utils.ResponseUtils;
import com.housekeeping.housekeeping.serviceItem.utils.StatUtil;
import com.housekeeping.housekeeping.wxPay.service.PayService;
import com.housekeeping.housekeeping.wxPay.service.impl.PayServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/PayServlet/wx/createOrder")
public class WXPayCreateOrderController extends HttpServlet {
    private PayService service=new PayServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String aid = RequestUtils.verify(req);
        String money = req.getParameter("money");
        aid="4399";
        //登录校验
        if (aid==null||money==null){
            ResponseUtils.fail(resp, StatUtil.NEED_LOGIN);
            return;
        }
        try {
            Long order=service.creatWXPayOrder(aid,Integer.parseInt(money));
            //成功
            if (order!=null){ResponseUtils.success(resp,order,StatUtil.SUCCESS);}
            else {ResponseUtils.fail(resp,StatUtil.SERVER_BUST);}
        } catch (SQLException troubles) {
            ResponseUtils.fail(resp,StatUtil.INTERNET_ERR);
            troubles.printStackTrace();
        }
    }
}
